<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import storage from '@/storage'
export default {
  name: 'app',
  data() {
    return {
      res: {}
    }
  },
  components: {},
  methods: {
    getUser() {
      this.axios.get('/user').then((res = {}) => {
        this.$store.dispatch('saveUserName', res.username)
        this.getCartCount()
      })
    },
    getCartCount() {
      this.axios.get('/carts/products/sum').then((res = 0) => {
        this.$store.dispatch('saveCartCount', res)
      })
    }
  },
  mounted() {
    if (this.$cookie.get('userId')) {
      this.getUser()
    }
    // storage.setItem('a', 123)
    // storage.setItem('asd', { a: 1, b: 2 }, 'user')
    // storage.clear('a')
    // storage.clear('asd', 'user')
    // 模拟数据，本地加载静态json文件的形式
    // this.axios.get('/mock/user/login.json').then(res => {
    //   console.log(res)
    // })
    // mockjs拦截 不会发送请求
    // this.axios.get('/user/login').then(res => {
    //   console.log(res)
    //   this.res = res
    // })
  }
}
</script>

<style scoped lang="scss">
@import './assets/scss/reset.scss';
@import './assets/scss/config.scss';
@import './assets/scss/button.scss';
</style>
